package com.doujiang.bus.service.impl;

import com.doujiang.bus.domain.Car;
import com.doujiang.bus.domain.Check;
import com.doujiang.bus.domain.Customer;
import com.doujiang.bus.domain.Rent;
import com.doujiang.bus.mapper.CarMapper;
import com.doujiang.bus.mapper.CustomerMapper;
import com.doujiang.bus.mapper.RentMapper;
import com.doujiang.bus.service.ICheckService;
import com.doujiang.sys.constant.SysConstant;
import com.doujiang.sys.domain.User;
import com.doujiang.sys.utils.RandomUtils;
import com.doujiang.sys.utils.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author：豆浆
 * @name :CheckServiceImpl
 * @Date：2023/12/21 20:15
 */
@Service
public class CheckServiceImpl implements ICheckService {

    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private RentMapper rentMapper;
    @Autowired
    private CarMapper carMapper;


    @Override
    public Map<String, Object> initCheckFormData(String rentid) {
        //查询出租单
        Rent rent = rentMapper.queryRentById(rentid);
        //查询客户
        Customer customer = customerMapper.selectByPrimaryKey(rent.getIdentity());
        //查询⻋辆
        Car car = carMapper.selectByPrimaryKey(rent.getCarnumber());
        //组装check对象
        Check check = new Check();
        check.setCheckid(RandomUtils.createRandomStringUseTime(SysConstant.CAR_ORDER_JC));
        check.setRentid(rentid);
        check.setCheckdate(new Date());
        User user =(User) WebUtils.getHttpSession().getAttribute("user");
        check.setOpername(user.getRealname());
        //数据组装
        Map<String, Object> map = new HashMap<>();
        map.put("rent",rent);
        map.put("customer",customer);
        map.put("car",car);
        map.put("check",check);
        return map;
    }
}
